// waveeditorDoc.h : interface of the CWaveeditorDoc class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_WAVEEDITORDOC_H__E2DE9C9B_B6EA_4986_B0E0_9F8EEDBDC6C5__INCLUDED_)
#define AFX_WAVEEDITORDOC_H__E2DE9C9B_B6EA_4986_B0E0_9F8EEDBDC6C5__INCLUDED_

//#include "mymessages.h"	// Added by ClassView
#include "languagecomponents.h"	// Added by ClassView
//#include "graphdata.h"	// Added by ClassView
#include "afxwin.h"
#include "documentpropertiesdialog.h"

enum TOOLSET { NORMALTOOL, ZOOMTOOL, SCROLLTOOL };

#define		STEPB				0
#define		STEPA				1
#define		STEPBNUM			0x72B1
#define		STEPANUM			0x72A0 
#define		VERSION_1			151
#define		VERSION_2			153
#define		VERSION_3			154
#define		MAXIMUMLINELENGTH	65535
#define		NUMBEROFPHASEDRIVE	9
#define		MAX_TIME_VALUE_IN_LOG 99999999
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

struct frameheader
{
	DWORD	FrameID;
	DWORD	OffSetToCode;
	DWORD	Size;
	DWORD	HTotal;
	DWORD	VTotal;
	DWORD	NFS;
//	DWORD	EXTRA[3];
} ;

struct binfileheader
{
	unsigned long		waveeditorversion;
	unsigned long		chipversion;
	unsigned short		NumberOffFramesInBinFile;
	short		global_phase;
	long		number_of_signals;	
//----- 	order of signals ADCLK ; DS1; DS2; R; H1; H2; H3; H4;
	short		rise	[NUMBEROFPHASEDRIVE];
	short		fall	[NUMBEROFPHASEDRIVE];
	short		drive	[NUMBEROFPHASEDRIVE];
//	unsigned long		reserved[17];
};

enum LineTypes
{
	INCORRECT_STRING,
	EMPTY_STRING,
	THREAD_NAME_STRING,
	BRACKETS_STRING,
	NO_BRACKETS_STRING
};

enum TimeTypes
{
	MICRO_SECONDS,
	MILLI_SECONDS
};

class ZWaveeditorDoc : public CDocument  
{
protected: // create from serialization only
									ZWaveeditorDoc					();
									DECLARE_DYNCREATE				(ZWaveeditorDoc)
		
	struct MOUSE_BUTTONS_STATE
	{
		bool LeftButton;
		bool RightButton;
		CPoint LastPosition;
		MOUSE_BUTTONS_STATE(): LeftButton( false ), RightButton( false ){ LastPosition.SetPoint(-1,0);}; 
	};
// Attributes
public:
// Implementation
	mymessages						StatusList;
	mymessages						templist;
	mymessages						filestocompress;
	int								selectedscenario;
	BOOL							treewaschanged;
//----------------------------------------------------------------
	int								graphwindowMaxX;
	HCURSOR							graphNormalCursor;
	HCURSOR							graphZoomCursor;
	HCURSOR                         graphScrollCursor;
	HCURSOR                         graphScrollCursorPush;
	MOUSE_BUTTONS_STATE				mouseButtonState;

	CRect							linesforselection[2];
	binfileheader					doc_fileheader;
	binfileheader					bin_fileheader;
	
public:
	CFrameWnd* editframe;
	CFrameWnd* graphframe;

public:
	CArray <scenario*,scenario*>					_script;
public:
	DocumentPropertiesDialog	PropertiesDialog;
	int							version;
	int							compressionstep;
	int							efectiveedge;//0== -ee 0,1 == -ee 1
	int							twopath;
	CString						compression_step_string[2];
	CString						GroupName;

protected:
	BOOL											EditWindowOpened;
	BOOL											bEnableGraphViewAlwaysShowHint;
	BOOL											GraphWindowOpened;
	CArray<struct frameheader,struct frameheader>	fheaders;
	CToolTipCtrl*									ptrGraphViewHint;
	CTreeCtrl*										last_tree;
	HTREEITEM										last_item;
	CString											phase_drive_tree_name;
	CString											phase_drive_names[NUMBEROFPHASEDRIVE];
	int												number_of_information_raws_in_frame;

public:
// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(ZWaveeditorDoc)
	public:
	virtual BOOL					OnNewDocument					();
	virtual void					Serialize						(CArchive& ar);
	virtual void					SetTitle						(LPCTSTR lpszTitle);
	virtual void					OnChangedViewList				();
	//}}AFX_VIRTUAL

public:
	void							RunCompressor					(CString inputfile,CString outputfile,CString HTotal,CString VTotal,CString VTotal_2,CString SubRes);
	CString							rebuild_string_to_command		(CString _line);
	void							SetGraphStatusBarText			( CArray<CString> *Texts, CArray<int> *Colors,
																		CArray<int> *Sizes, int StatusBarIndex  );
	void							SetDispStatusBar0Value			( int StartNum1, int StartNum2, int StartNum3);
	BOOL							CheckIfEditWindowOpened			();
	BOOL							CheckIfGraphWindowOpened		();
	bool						    GetGraphViewHintState			() const;
	void							SetGraphVeiwHintState			( bool NewState );
	int								ExportTree						(CTreeCtrl *_tree,DWORD num);
	CString							GetPathOnly						();
	void							OnDeleteselectedscript			(HTREEITEM pos);
	int								OnEditscriptSave				(CEdit *_myedit, int SelectedScenario);
	int								OnEditscriptRun					(CEdit *_edit, int SelectedScenario);
	void							LoadScriptOrLogFromSOW			( CArchive& ar );
	void							LoadScriptOrLogFromSRP			( CString FileName );
	bool							LoadScriptFile					( CString filename, scenario* newscenario );
	void							MultiRunCompressor				(CString outputname);
	void							SetEditWindowOpened				();
	void							SetGraphWindowOpened			();
	void							OnAddScriptOrLog				();
	void							OnEditscriptfile				(CTreeCtrl *_tree,HTREEITEM _item);
	int								OnGraphViewFromTree				(CTreeCtrl  *_tree,HTREEITEM _item);
	int								OnGraphView						( int SelectedScenarioNumber, CString GroupName );
	int								OnItemInfo						(CTreeCtrl *_tree,HTREEITEM _item);
	int								OnSavealltovectorfile			();
	int								OnSavetovectorfile				(CTreeCtrl *_tree,HTREEITEM _item);
	int								PrepaireNewBinFile				(CString filename);
	void							UpdateScriptFromSelection		(HTREEITEM pos);
	void							SetGraphViewHintPointer			( CToolTipCtrl* ptrToolTip );
	void							SetEditWindowClosed				();
	void							SetGraphWindowClosed			();
	CString							GetGroupName 					() const;
	virtual							~ZWaveeditorDoc					();
#ifdef _DEBUG
	virtual void									AssertValid	() const;
	virtual void									Dump		(CDumpContext& dc) const;
#endif

// Generated message map functions
public:
	//{{AFX_MSG(ZWaveeditorDoc)
	afx_msg void					OnDocumentproperties();
	afx_msg void					OnFileSave();
	afx_msg void					OnFileSaveAs();
	//}}AFX_MSG
									DECLARE_MESSAGE_MAP				()
public:
	void						FinilizeBinFile		(CString filename);
	int							ExportTreeGlobalValues	(CTreeCtrl* _tree, DWORD num);
	void						OnEditGlobalValues		(mymessages* templist);
	void						OnEditSaveGlobalValues	(mymessages* templist);
	int							CheckIfGlobalPhase		(CString scriptline);
	int							CheckIfPhase			(CString scriptline);
	int							CheckIfDrive			(CString scriptline);
	int							GetNumberFromString		(CString snumber);
	CString						GetStringFromNumber		(int number);
	int							BinFileHeaderSerialize	(CArchive& ar);
	void						PrepearBinFileHeader	(void);
	afx_msg void				OnAlwaysShowHint		();
	void						OnReloadLogWithChosenProperties( int NumberOfScenario );

	//Helper functions
private:
	enum LineTypes				GetLineType( CString Line );
	void						HandleLines(CStdioFile &LogFile,
											CArray< Signal, Signal > *Signals,
											unsigned __int64& TotalSize, 
											LogReadingType TypeOfReading );
	BOOL						GetValuesFromLogFile( CString filename, 
		                                              CArray< Signal, Signal > *Signals, 
													  unsigned __int64 &TotalSize, 
													  LogReadingType TypeOfReading );
	void						GetValuesFromString( CString Line, LineMembers *LineMembrs );
	void						AddNewTimingMark ( LineMembers LineMembrs, CArray< Signal, Signal > *Signals );
	void						ConvertOldSignalValuesToScriptCompatible( CArray< Signal, Signal > &Signals );
	void						FillTemporaryFiles( const CArray< Signal, Signal > &Signals,
													CStdioFile * TemporarySRP,
													long TotalSize );
	void						CloseGraphWindow();
	void						CloseEditWindow();
	void						FillTempListWithDataFromEditFrame( int numoflines, CEdit *_myedit);
	void						ExcludeUnnecessarySignals( CArray< Signal, Signal > &SignalsLog,
														   LogReadingType ReadType,
														   scenario *OldScenario );
	void						ExcludeUnnecessarySignalsForChosenType( CArray< Signal, Signal > &Signals,
																		LogReadingType ReadType, 
																		long (LogReadingType::*TypeOfChosenLines),
																		long TypeOfLineInSignals,
																		scenario *OldScenario );
	CString						CreateSRPFile( CString OldFileName, const CArray< Signal, Signal > &Signals, long TotalSize );
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_WAVEEDITORDOC_H__E2DE9C9B_B6EA_4986_B0E0_9F8EEDBDC6C5__INCLUDED_)
#pragma once


